module.exports = `<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8">
        <title>{{name}}分类编辑</title>
        <meta name="renderer" content="webkit">
        <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
        <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
        <link rel="stylesheet" href="../../component/ui/css/ui.css"/>
    </head>
    <body>
        <form class="layui-form" action="" lay-filter="editform">
            <div class="mainBox">
                <div class="main-container">
                    <div class="main-container">
                        <div class="layui-form-item">
                            <label class="layui-form-label">分类名称</label>
                            <div class="layui-input-block">
                                <input type="text" name="name" lay-verify="required|len" autocomplete="off" min="1" placeholder="请输入名称" class="layui-input">
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <label class="layui-form-label">上级</label>
                            <div class="layui-input-block">
                                <span class="layui-btn pear-btn-success pear-btn-md" id="chooseArea">
                                    <span id="areaText">顶层</span>
                                    <i class="layui-icon layui-icon-down layui-font-12"></i>
                                </span>
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <label class="layui-form-label">地区排序</label>
                            <div class="layui-input-block">
                                <input type="number" name="order_num" value="0" autocomplete="off" placeholder="请输入地区排序" class="layui-input">
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <label class="layui-form-label">是否启用</label>
                            <div class="layui-input-block">
                            <input type="radio" name="status" value="1" title="启用" checked="">
                            <input type="radio" name="status" value="0" title="禁用">
                            </div>
                        </div>

                    </div>
                </div>
            </div>
            <div class="bottom">
                <div class="button-container">
                    <input type="hidden" name="pid" id="pid" lay-verify="required|number" value="0">
                    <button type="submit" class="pear-btn pear-btn-primary pear-btn-sm" lay-submit="" lay-filter="area-save">
                        <i class="layui-icon layui-icon-ok"></i>
                提交
            </button>
                </div>
            </div>
        </form>
        <script src="../../config/config.js"></script>
        <script src="../../component/layui/layui.js"></script>
        <script src="../../component/ui/ui.js"></script>
        <script>
            layui.use([
                'form', 'layer', 'dropdown'
            ], function () {
                let form = layui.form,
                    layer = layui.layer,
                    $ = layui.$,
                    dropdown = layui.dropdown,
                    req = _req();
                form.verify({
                    len: (val, item) => {
                        let min = item.getAttribute("min")
                        if (val.length < min) {
                            return '长度不能小于' + min;
                        }
                    }
                })
                if (req.id) {
                    //渲染
                    _get(layui, '{{key}}/cateEditBefore?id=' + req.id, res => {
                        form.val('editform', res)
                        dropdown.render({
                            elem: '#chooseArea',
                            data: res.list,
                            trigger: 'hover',
                            click: (d, el) => {
                                $('#areaText').text(d.title);
                                $('#pid').val(d.id);
                                return;
                            }
                        })
                        $('#areaText').text(res.cname);
                    });
                } else {
                    _get(layui, '{{key}}/cateAddBefore', res => {
                        console.log(res)
                        dropdown.render({
                            elem: '#chooseArea',
                            data: res,
                            trigger: 'hover',
                            click: (d, el) => {
                                $('#areaText').text(d.title);
                                $('#pid').val(d.id);
                                return;
                            }
                        })
                    });
                }

                //监听提交
                form.on('submit(area-save)', function (data) {
                    data = data.field;
                    let postUrl;
                    if (req.id) {
                        postUrl = '{{key}}/cateEdit';
                    } else {
                        postUrl = '{{key}}/cateAdd';
                    }
                    _post(layui, postUrl, data, res => {
                        //console.log(res)
                        /*parent
                            .layui
                            .table
                            .reload("area-table");*/
                        parent
                            .layer
                            .close(parent.layer.getFrameIndex(window.name)); //关闭当前页

                    })

                    return false;
                });

            });
        </script>

    </body>
</html>`;